
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>枚举 · TypeScript Handbook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Patrick Zhong">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Type Inference.html" />
    
    
    <link rel="prev" href="Generics.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="tutorials/">
            
                <a href="tutorials/">
            
                    
                    快速上手
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="tutorials/TypeScript in 5 minutes.html">
            
                <a href="tutorials/TypeScript in 5 minutes.html">
            
                    
                    5分钟了解TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="tutorials/ASP.NET Core.html">
            
                <a href="tutorials/ASP.NET Core.html">
            
                    
                    ASP.NET Core
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="tutorials/ASP.NET 4.html">
            
                <a href="tutorials/ASP.NET 4.html">
            
                    
                    ASP.NET 4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="tutorials/Gulp.html">
            
                <a href="tutorials/Gulp.html">
            
                    
                    Gulp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="tutorials/Knockout.html">
            
                <a href="tutorials/Knockout.html">
            
                    
                    Knockout.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="tutorials/React & Webpack.html">
            
                <a href="tutorials/React & Webpack.html">
            
                    
                    React与webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="tutorials/React.html">
            
                <a href="tutorials/React.html">
            
                    
                    React
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="tutorials/Angular 2.html">
            
                <a href="tutorials/Angular 2.html">
            
                    
                    Angular 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="tutorials/Migrating from JavaScript.html">
            
                <a href="tutorials/Migrating from JavaScript.html">
            
                    
                    从JavaScript迁移到TypeScript
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    手册
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="Basic Types.html">
            
                <a href="Basic Types.html">
            
                    
                    基础类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="Variable Declarations.html">
            
                <a href="Variable Declarations.html">
            
                    
                    变量声明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="Interfaces.html">
            
                <a href="Interfaces.html">
            
                    
                    接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="Classes.html">
            
                <a href="Classes.html">
            
                    
                    类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="Functions.html">
            
                <a href="Functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="Generics.html">
            
                <a href="Generics.html">
            
                    
                    泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.7" data-path="Enums.html">
            
                <a href="Enums.html">
            
                    
                    枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="Type Inference.html">
            
                <a href="Type Inference.html">
            
                    
                    类型推论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="Type Compatibility.html">
            
                <a href="Type Compatibility.html">
            
                    
                    类型兼容性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="Advanced Types.html">
            
                <a href="Advanced Types.html">
            
                    
                    高级类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="Utilit Types.md">
            
                <span>
            
                    
                    实用工具类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="Symbols.html">
            
                <a href="Symbols.html">
            
                    
                    Symbols
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="Iterators and Generators.html">
            
                <a href="Iterators and Generators.html">
            
                    
                    Iterators 和 Generators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.14" data-path="Modules.html">
            
                <a href="Modules.html">
            
                    
                    模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.15" data-path="Namespaces.html">
            
                <a href="Namespaces.html">
            
                    
                    命名空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.16" data-path="Namespaces and Modules.html">
            
                <a href="Namespaces and Modules.html">
            
                    
                    命名空间和模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.17" data-path="Module Resolution.html">
            
                <a href="Module Resolution.html">
            
                    
                    模块解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.18" data-path="Declaration Merging.html">
            
                <a href="Declaration Merging.html">
            
                    
                    声明合并
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.19" data-path="Writing Definition Files.html">
            
                <a href="Writing Definition Files.html">
            
                    
                    书写.d.ts文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.20" data-path="JSX.html">
            
                <a href="JSX.html">
            
                    
                    JSX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.21" data-path="Decorators.html">
            
                <a href="Decorators.html">
            
                    
                    Decorators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.22" data-path="Mixins.html">
            
                <a href="Mixins.html">
            
                    
                    混入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.23" data-path="Triple-Slash Directives.html">
            
                <a href="Triple-Slash Directives.html">
            
                    
                    三斜线指令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.24" data-path="Type Checking JavaScript Files.html">
            
                <a href="Type Checking JavaScript Files.html">
            
                    
                    JavaScript文件里的类型检查
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="declaration files/Introduction.html">
            
                <a href="declaration files/Introduction.html">
            
                    
                    如何书写声明文件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="declaration files/Library Structures.html">
            
                <a href="declaration files/Library Structures.html">
            
                    
                    结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="declaration files/Do's and Don'ts.html">
            
                <a href="declaration files/Do's and Don'ts.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="declaration files/By Example.html">
            
                <a href="declaration files/By Example.html">
            
                    
                    举例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="declaration files/Deep Dive.html">
            
                <a href="declaration files/Deep Dive.html">
            
                    
                    深入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="declaration files/Publishing.html">
            
                <a href="declaration files/Publishing.html">
            
                    
                    发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="declaration files/Consumption.html">
            
                <a href="declaration files/Consumption.html">
            
                    
                    使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="tsconfig.json.html">
            
                <a href="tsconfig.json.html">
            
                    
                    工程配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="tsconfig.json.html">
            
                <a href="tsconfig.json.html">
            
                    
                    tsconfig.json
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="Project References.html">
            
                <a href="Project References.html">
            
                    
                    工程引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="Typings for NPM Packages.html">
            
                <a href="Typings for NPM Packages.html">
            
                    
                    NPM包的类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="Compiler Options.html">
            
                <a href="Compiler Options.html">
            
                    
                    编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="Configuring Watch.html">
            
                <a href="Configuring Watch.html">
            
                    
                    配置 Watch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="Compiler Options in MSBuild.html">
            
                <a href="Compiler Options in MSBuild.html">
            
                    
                    在MSBuild里使用编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="Integrating with Build Tools.html">
            
                <a href="Integrating with Build Tools.html">
            
                    
                    与其它构建工具整合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="Nightly Builds.html">
            
                <a href="Nightly Builds.html">
            
                    
                    使用TypeScript的每日构建版本
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../wiki/">
            
                <a href="../wiki/">
            
                    
                    Wiki
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../wiki/this-in-TypeScript.html">
            
                <a href="../wiki/this-in-TypeScript.html">
            
                    
                    TypeScript里的this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../wiki/coding_guidelines.html">
            
                <a href="../wiki/coding_guidelines.html">
            
                    
                    编码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../wiki/Common Errors.html">
            
                <a href="../wiki/Common Errors.html">
            
                    
                    常见编译错误
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../wiki/TypeScript-Editor-Support.html">
            
                <a href="../wiki/TypeScript-Editor-Support.html">
            
                    
                    支持TypeScript的编辑器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                <a href="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                    
                    结合ASP.NET v5使用TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../wiki/Architectural-Overview.html">
            
                <a href="../wiki/Architectural-Overview.html">
            
                    
                    架构概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../wiki/Roadmap.html">
            
                <a href="../wiki/Roadmap.html">
            
                    
                    发展路线图
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../release-notes/">
            
                <a href="../release-notes/">
            
                    
                    新增功能
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../release-notes/TypeScript 3.1.html">
            
                <a href="../release-notes/TypeScript 3.1.html">
            
                    
                    TypeScript 3.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../release-notes/TypeScript 3.0.html">
            
                <a href="../release-notes/TypeScript 3.0.html">
            
                    
                    TypeScript 3.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../release-notes/TypeScript 2.9.html">
            
                <a href="../release-notes/TypeScript 2.9.html">
            
                    
                    TypeScript 2.9
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../release-notes/TypeScript 2.8.html">
            
                <a href="../release-notes/TypeScript 2.8.html">
            
                    
                    TypeScript 2.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../release-notes/TypeScript 2.7.html">
            
                <a href="../release-notes/TypeScript 2.7.html">
            
                    
                    TypeScript 2.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../release-notes/TypeScript 2.6.html">
            
                <a href="../release-notes/TypeScript 2.6.html">
            
                    
                    TypeScript 2.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../release-notes/TypeScript 2.5.html">
            
                <a href="../release-notes/TypeScript 2.5.html">
            
                    
                    TypeScript 2.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../release-notes/TypeScript 2.4.html">
            
                <a href="../release-notes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../release-notes/TypeScript 2.3.html">
            
                <a href="../release-notes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../release-notes/TypeScript 2.2.html">
            
                <a href="../release-notes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.11" data-path="../release-notes/TypeScript 2.1.html">
            
                <a href="../release-notes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.12" data-path="../release-notes/TypeScript 2.0.html">
            
                <a href="../release-notes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.13" data-path="../release-notes/TypeScript 1.8.html">
            
                <a href="../release-notes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.14" data-path="../release-notes/TypeScript 1.7.html">
            
                <a href="../release-notes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.15" data-path="../release-notes/TypeScript 1.6.html">
            
                <a href="../release-notes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.16" data-path="../release-notes/TypeScript 1.5.html">
            
                <a href="../release-notes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.17" data-path="../release-notes/TypeScript 1.4.html">
            
                <a href="../release-notes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.18" data-path="../release-notes/TypeScript 1.3.html">
            
                <a href="../release-notes/TypeScript 1.3.html">
            
                    
                    TypeScript 1.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.19" data-path="../release-notes/TypeScript 1.1.html">
            
                <a href="../release-notes/TypeScript 1.1.html">
            
                    
                    TypeScript 1.1
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../breaking-changes/breaking-changes.html">
            
                <a href="../breaking-changes/breaking-changes.html">
            
                    
                    Breaking Changes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../breaking-changes/TypeScript 2.4.html">
            
                <a href="../breaking-changes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../breaking-changes/TypeScript 2.3.html">
            
                <a href="../breaking-changes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../breaking-changes/TypeScript 2.2.html">
            
                <a href="../breaking-changes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../breaking-changes/TypeScript 2.1.html">
            
                <a href="../breaking-changes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../breaking-changes/TypeScript 2.0.html">
            
                <a href="../breaking-changes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../breaking-changes/TypeScript 1.8.html">
            
                <a href="../breaking-changes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../breaking-changes/TypeScript 1.7.html">
            
                <a href="../breaking-changes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../breaking-changes/TypeScript 1.6.html">
            
                <a href="../breaking-changes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../breaking-changes/TypeScript 1.5.html">
            
                <a href="../breaking-changes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" data-path="../breaking-changes/TypeScript 1.4.html">
            
                <a href="../breaking-changes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >枚举</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x679A;&#x4E3E;">&#x679A;&#x4E3E;</h1>
<p>&#x4F7F;&#x7528;&#x679A;&#x4E3E;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x4E00;&#x4E9B;&#x5E26;&#x540D;&#x5B57;&#x7684;&#x5E38;&#x91CF;&#x3002;
&#x4F7F;&#x7528;&#x679A;&#x4E3E;&#x53EF;&#x4EE5;&#x6E05;&#x6670;&#x5730;&#x8868;&#x8FBE;&#x610F;&#x56FE;&#x6216;&#x521B;&#x5EFA;&#x4E00;&#x7EC4;&#x6709;&#x533A;&#x522B;&#x7684;&#x7528;&#x4F8B;&#x3002;
TypeScript&#x652F;&#x6301;&#x6570;&#x5B57;&#x7684;&#x548C;&#x57FA;&#x4E8E;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x679A;&#x4E3E;&#x3002;</p>
<h2 id="&#x6570;&#x5B57;&#x679A;&#x4E3E;">&#x6570;&#x5B57;&#x679A;&#x4E3E;</h2>
<p>&#x9996;&#x5148;&#x6211;&#x4EEC;&#x770B;&#x770B;&#x6570;&#x5B57;&#x679A;&#x4E3E;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x4F7F;&#x7528;&#x8FC7;&#x5176;&#x5B83;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x5E94;&#x8BE5;&#x4F1A;&#x5F88;&#x719F;&#x6089;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> Direction {
    Up = <span class="hljs-number">1</span>,
    Down,
    Left,
    Right
}
</code></pre>
<p>&#x5982;&#x4E0A;&#xFF0C;&#x6211;&#x4EEC;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x6570;&#x5B57;&#x679A;&#x4E3E;&#xFF0C;<code>Up</code>&#x4F7F;&#x7528;&#x521D;&#x59CB;&#x5316;&#x4E3A;<code>1</code>&#x3002;
&#x5176;&#x4F59;&#x7684;&#x6210;&#x5458;&#x4F1A;&#x4ECE;<code>1</code>&#x5F00;&#x59CB;&#x81EA;&#x52A8;&#x589E;&#x957F;&#x3002;
&#x6362;&#x53E5;&#x8BDD;&#x8BF4;&#xFF0C;<code>Direction.Up</code>&#x7684;&#x503C;&#x4E3A;<code>1</code>&#xFF0C;<code>Down</code>&#x4E3A;<code>2</code>&#xFF0C;<code>Left</code>&#x4E3A;<code>3</code>&#xFF0C;<code>Right</code>&#x4E3A;<code>4</code>&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x5B8C;&#x5168;&#x4E0D;&#x4F7F;&#x7528;&#x521D;&#x59CB;&#x5316;&#x5668;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> Direction {
    Up,
    Down,
    Left,
    Right,
}
</code></pre>
<p>&#x73B0;&#x5728;&#xFF0C;<code>Up</code>&#x7684;&#x503C;&#x4E3A;<code>0</code>&#xFF0C;<code>Down</code>&#x7684;&#x503C;&#x4E3A;<code>1</code>&#x7B49;&#x7B49;&#x3002;
&#x5F53;&#x6211;&#x4EEC;&#x4E0D;&#x5728;&#x4E4E;&#x6210;&#x5458;&#x7684;&#x503C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8FD9;&#x79CD;&#x81EA;&#x589E;&#x957F;&#x7684;&#x884C;&#x4E3A;&#x662F;&#x5F88;&#x6709;&#x7528;&#x5904;&#x7684;&#xFF0C;&#x4F46;&#x662F;&#x8981;&#x6CE8;&#x610F;&#x6BCF;&#x4E2A;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;&#x503C;&#x90FD;&#x662F;&#x4E0D;&#x540C;&#x7684;&#x3002;</p>
<p>&#x4F7F;&#x7528;&#x679A;&#x4E3E;&#x5F88;&#x7B80;&#x5355;&#xFF1A;&#x901A;&#x8FC7;&#x679A;&#x4E3E;&#x7684;&#x5C5E;&#x6027;&#x6765;&#x8BBF;&#x95EE;&#x679A;&#x4E3E;&#x6210;&#x5458;&#xFF0C;&#x548C;&#x679A;&#x4E3E;&#x7684;&#x540D;&#x5B57;&#x6765;&#x8BBF;&#x95EE;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> Response {
    No = <span class="hljs-number">0</span>,
    Yes = <span class="hljs-number">1</span>,
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">respond</span>(<span class="hljs-params">recipient: <span class="hljs-built_in">string</span>, message: Response</span>): <span class="hljs-title">void</span> </span>{
    <span class="hljs-comment">// ...</span>
}

respond(<span class="hljs-string">&quot;Princess Caroline&quot;</span>, Response.Yes)
</code></pre>
<p>&#x6570;&#x5B57;&#x679A;&#x4E3E;&#x53EF;&#x4EE5;&#x88AB;&#x6DF7;&#x5165;&#x5230;<a href="#computed-and-constant-members">&#x8BA1;&#x7B97;&#x8FC7;&#x7684;&#x548C;&#x5E38;&#x91CF;&#x6210;&#x5458;&#xFF08;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF09;</a>&#x3002;
&#x7B80;&#x77ED;&#x5730;&#x8BF4;&#xFF0C;&#x4E0D;&#x5E26;&#x521D;&#x59CB;&#x5316;&#x5668;&#x7684;&#x679A;&#x4E3E;&#x6216;&#x8005;&#x88AB;&#x653E;&#x5728;&#x7B2C;&#x4E00;&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x6216;&#x8005;&#x88AB;&#x653E;&#x5728;&#x4F7F;&#x7528;&#x4E86;&#x6570;&#x5B57;&#x5E38;&#x91CF;&#x6216;&#x5176;&#x5B83;&#x5E38;&#x91CF;&#x521D;&#x59CB;&#x5316;&#x4E86;&#x7684;&#x679A;&#x4E3E;&#x540E;&#x9762;&#x3002;
&#x6362;&#x53E5;&#x8BDD;&#x8BF4;&#xFF0C;&#x4E0B;&#x9762;&#x7684;&#x60C5;&#x51B5;&#x662F;&#x4E0D;&#x88AB;&#x5141;&#x8BB8;&#x7684;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> E {
    A = getSomeValue(),
    B, <span class="hljs-comment">// error! &apos;A&apos; is not constant-initialized, so &apos;B&apos; needs an initializer</span>
}
</code></pre>
<h2 id="&#x5B57;&#x7B26;&#x4E32;&#x679A;&#x4E3E;">&#x5B57;&#x7B26;&#x4E32;&#x679A;&#x4E3E;</h2>
<p>&#x5B57;&#x7B26;&#x4E32;&#x679A;&#x4E3E;&#x7684;&#x6982;&#x5FF5;&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x4F46;&#x662F;&#x6709;&#x7EC6;&#x5FAE;&#x7684;<a href="#enums-at-runtime">&#x8FD0;&#x884C;&#x65F6;&#x7684;&#x5DEE;&#x522B;</a>&#x3002;
&#x5728;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x679A;&#x4E3E;&#x91CC;&#xFF0C;&#x6BCF;&#x4E2A;&#x6210;&#x5458;&#x90FD;&#x5FC5;&#x987B;&#x7528;&#x5B57;&#x7B26;&#x4E32;&#x5B57;&#x9762;&#x91CF;&#xFF0C;&#x6216;&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x8FDB;&#x884C;&#x521D;&#x59CB;&#x5316;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> Direction {
    Up = <span class="hljs-string">&quot;UP&quot;</span>,
    Down = <span class="hljs-string">&quot;DOWN&quot;</span>,
    Left = <span class="hljs-string">&quot;LEFT&quot;</span>,
    Right = <span class="hljs-string">&quot;RIGHT&quot;</span>,
}
</code></pre>
<p>&#x7531;&#x4E8E;&#x5B57;&#x7B26;&#x4E32;&#x679A;&#x4E3E;&#x6CA1;&#x6709;&#x81EA;&#x589E;&#x957F;&#x7684;&#x884C;&#x4E3A;&#xFF0C;&#x5B57;&#x7B26;&#x4E32;&#x679A;&#x4E3E;&#x53EF;&#x4EE5;&#x5F88;&#x597D;&#x7684;&#x5E8F;&#x5217;&#x5316;&#x3002;
&#x6362;&#x53E5;&#x8BDD;&#x8BF4;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x6B63;&#x5728;&#x8C03;&#x8BD5;&#x5E76;&#x4E14;&#x5FC5;&#x987B;&#x8981;&#x8BFB;&#x4E00;&#x4E2A;&#x6570;&#x5B57;&#x679A;&#x4E3E;&#x7684;&#x8FD0;&#x884C;&#x65F6;&#x7684;&#x503C;&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x901A;&#x5E38;&#x662F;&#x5F88;&#x96BE;&#x8BFB;&#x7684; - &#x5B83;&#x5E76;&#x4E0D;&#x80FD;&#x8868;&#x8FBE;&#x6709;&#x7528;&#x7684;&#x4FE1;&#x606F;&#xFF08;&#x5C3D;&#x7BA1;<a href="#enums-at-runtime">&#x53CD;&#x5411;&#x6620;&#x5C04;</a>&#x4F1A;&#x6709;&#x6240;&#x5E2E;&#x52A9;&#xFF09;&#xFF0C;&#x5B57;&#x7B26;&#x4E32;&#x679A;&#x4E3E;&#x5141;&#x8BB8;&#x4F60;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x8FD0;&#x884C;&#x65F6;&#x6709;&#x610F;&#x4E49;&#x7684;&#x5E76;&#x4E14;&#x53EF;&#x8BFB;&#x7684;&#x503C;&#xFF0C;&#x72EC;&#x7ACB;&#x4E8E;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;&#x540D;&#x5B57;&#x3002;</p>
<h2 id="&#x5F02;&#x6784;&#x679A;&#x4E3E;&#xFF08;heterogeneous-enums&#xFF09;">&#x5F02;&#x6784;&#x679A;&#x4E3E;&#xFF08;Heterogeneous enums&#xFF09;</h2>
<p>&#x4ECE;&#x6280;&#x672F;&#x7684;&#x89D2;&#x5EA6;&#x6765;&#x8BF4;&#xFF0C;&#x679A;&#x4E3E;&#x53EF;&#x4EE5;&#x6DF7;&#x5408;&#x5B57;&#x7B26;&#x4E32;&#x548C;&#x6570;&#x5B57;&#x6210;&#x5458;&#xFF0C;&#x4F46;&#x662F;&#x4F3C;&#x4E4E;&#x4F60;&#x5E76;&#x4E0D;&#x4F1A;&#x8FD9;&#x4E48;&#x505A;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> BooleanLikeHeterogeneousEnum {
    No = <span class="hljs-number">0</span>,
    Yes = <span class="hljs-string">&quot;YES&quot;</span>,
}
</code></pre>
<p>&#x9664;&#x975E;&#x4F60;&#x771F;&#x7684;&#x60F3;&#x8981;&#x5229;&#x7528;JavaScript&#x8FD0;&#x884C;&#x65F6;&#x7684;&#x884C;&#x4E3A;&#xFF0C;&#x5426;&#x5219;&#x6211;&#x4EEC;&#x4E0D;&#x5EFA;&#x8BAE;&#x8FD9;&#x6837;&#x505A;&#x3002;</p>
<h2 id="&#x8BA1;&#x7B97;&#x7684;&#x548C;&#x5E38;&#x91CF;&#x6210;&#x5458;">&#x8BA1;&#x7B97;&#x7684;&#x548C;&#x5E38;&#x91CF;&#x6210;&#x5458;</h2>
<p>&#x6BCF;&#x4E2A;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x90FD;&#x5E26;&#x6709;&#x4E00;&#x4E2A;&#x503C;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x662F;<em>&#x5E38;&#x91CF;</em>&#x6216;<em>&#x8BA1;&#x7B97;&#x51FA;&#x6765;&#x7684;</em>&#x3002;
&#x5F53;&#x6EE1;&#x8DB3;&#x5982;&#x4E0B;&#x6761;&#x4EF6;&#x65F6;&#xFF0C;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x88AB;&#x5F53;&#x4F5C;&#x662F;&#x5E38;&#x91CF;&#xFF1A;</p>
<ul>
<li><p>&#x5B83;&#x662F;&#x679A;&#x4E3E;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x6210;&#x5458;&#x4E14;&#x6CA1;&#x6709;&#x521D;&#x59CB;&#x5316;&#x5668;&#xFF0C;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#x5B83;&#x88AB;&#x8D4B;&#x4E88;&#x503C;<code>0</code>&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-comment">// E.X is constant:</span>
<span class="hljs-keyword">enum</span> E { X }
</code></pre>
</li>
<li><p>&#x5B83;&#x4E0D;&#x5E26;&#x6709;&#x521D;&#x59CB;&#x5316;&#x5668;&#x4E14;&#x5B83;&#x4E4B;&#x524D;&#x7684;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x662F;&#x4E00;&#x4E2A;<em>&#x6570;&#x5B57;</em>&#x5E38;&#x91CF;&#x3002;
&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5F53;&#x524D;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;&#x503C;&#x4E3A;&#x5B83;&#x4E0A;&#x4E00;&#x4E2A;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;&#x503C;&#x52A0;1&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-comment">// All enum members in &apos;E1&apos; and &apos;E2&apos; are constant.</span>

<span class="hljs-keyword">enum</span> E1 { X, Y, Z }

<span class="hljs-keyword">enum</span> E2 {
    A = <span class="hljs-number">1</span>, B, C
}
</code></pre>
</li>
<li><p>&#x679A;&#x4E3E;&#x6210;&#x5458;&#x4F7F;&#x7528;<em>&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x8868;&#x8FBE;&#x5F0F;</em>&#x521D;&#x59CB;&#x5316;&#x3002;
&#x5E38;&#x6570;&#x679A;&#x4E3E;&#x8868;&#x8FBE;&#x5F0F;&#x662F;TypeScript&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x5B50;&#x96C6;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x5728;&#x7F16;&#x8BD1;&#x9636;&#x6BB5;&#x6C42;&#x503C;&#x3002;
&#x5F53;&#x4E00;&#x4E2A;&#x8868;&#x8FBE;&#x5F0F;&#x6EE1;&#x8DB3;&#x4E0B;&#x9762;&#x6761;&#x4EF6;&#x4E4B;&#x4E00;&#x65F6;&#xFF0C;&#x5B83;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x8868;&#x8FBE;&#x5F0F;&#xFF1A;</p>
<ul>
<li>&#x4E00;&#x4E2A;&#x679A;&#x4E3E;&#x8868;&#x8FBE;&#x5F0F;&#x5B57;&#x9762;&#x91CF;&#xFF08;&#x4E3B;&#x8981;&#x662F;&#x5B57;&#x7B26;&#x4E32;&#x5B57;&#x9762;&#x91CF;&#x6216;&#x6570;&#x5B57;&#x5B57;&#x9762;&#x91CF;&#xFF09;</li>
<li>&#x4E00;&#x4E2A;&#x5BF9;&#x4E4B;&#x524D;&#x5B9A;&#x4E49;&#x7684;&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;&#x5F15;&#x7528;&#xFF08;&#x53EF;&#x4EE5;&#x662F;&#x5728;&#x4E0D;&#x540C;&#x7684;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#xFF09;</li>
<li>&#x5E26;&#x62EC;&#x53F7;&#x7684;&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x8868;&#x8FBE;&#x5F0F;</li>
<li>&#x4E00;&#x5143;&#x8FD0;&#x7B97;&#x7B26;<code>+</code>, <code>-</code>, <code>~</code>&#x5176;&#x4E2D;&#x4E4B;&#x4E00;&#x5E94;&#x7528;&#x5728;&#x4E86;&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x8868;&#x8FBE;&#x5F0F;</li>
<li>&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x8868;&#x8FBE;&#x5F0F;&#x505A;&#x4E3A;&#x4E8C;&#x5143;&#x8FD0;&#x7B97;&#x7B26;<code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code>, <code>&lt;&lt;</code>, <code>&gt;&gt;</code>, <code>&gt;&gt;&gt;</code>, <code>&amp;</code>, <code>|</code>, <code>^</code>&#x7684;&#x64CD;&#x4F5C;&#x5BF9;&#x8C61;&#x3002;
&#x82E5;&#x5E38;&#x6570;&#x679A;&#x4E3E;&#x8868;&#x8FBE;&#x5F0F;&#x6C42;&#x503C;&#x540E;&#x4E3A;<code>NaN</code>&#x6216;<code>Infinity</code>&#xFF0C;&#x5219;&#x4F1A;&#x5728;&#x7F16;&#x8BD1;&#x9636;&#x6BB5;&#x62A5;&#x9519;&#x3002;</li>
</ul>
</li>
</ul>
<p>&#x6240;&#x6709;&#x5176;&#x5B83;&#x60C5;&#x51B5;&#x7684;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x88AB;&#x5F53;&#x4F5C;&#x662F;&#x9700;&#x8981;&#x8BA1;&#x7B97;&#x5F97;&#x51FA;&#x7684;&#x503C;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> FileAccess {
    <span class="hljs-comment">// constant members</span>
    None,
    Read    = <span class="hljs-number">1</span> &lt;&lt; <span class="hljs-number">1</span>,
    Write   = <span class="hljs-number">1</span> &lt;&lt; <span class="hljs-number">2</span>,
    ReadWrite  = Read | Write,
    <span class="hljs-comment">// computed member</span>
    G = <span class="hljs-string">&quot;123&quot;</span>.length
}
</code></pre>
<h2 id="&#x8054;&#x5408;&#x679A;&#x4E3E;&#x4E0E;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;&#x7C7B;&#x578B;">&#x8054;&#x5408;&#x679A;&#x4E3E;&#x4E0E;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;&#x7C7B;&#x578B;</h2>
<p>&#x5B58;&#x5728;&#x4E00;&#x79CD;&#x7279;&#x6B8A;&#x7684;&#x975E;&#x8BA1;&#x7B97;&#x7684;&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;&#x5B50;&#x96C6;&#xFF1A;&#x5B57;&#x9762;&#x91CF;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x3002;
&#x5B57;&#x9762;&#x91CF;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x662F;&#x6307;&#x4E0D;&#x5E26;&#x6709;&#x521D;&#x59CB;&#x503C;&#x7684;&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x6210;&#x5458;&#xFF0C;&#x6216;&#x8005;&#x662F;&#x503C;&#x88AB;&#x521D;&#x59CB;&#x5316;&#x4E3A;</p>
<ul>
<li>&#x4EFB;&#x4F55;&#x5B57;&#x7B26;&#x4E32;&#x5B57;&#x9762;&#x91CF;&#xFF08;&#x4F8B;&#x5982;&#xFF1A;<code>&quot;foo&quot;</code>&#xFF0C;<code>&quot;bar&quot;</code>&#xFF0C;<code>&quot;baz&quot;</code>&#xFF09;</li>
<li>&#x4EFB;&#x4F55;&#x6570;&#x5B57;&#x5B57;&#x9762;&#x91CF;&#xFF08;&#x4F8B;&#x5982;&#xFF1A;<code>1</code>, <code>100</code>&#xFF09;</li>
<li>&#x5E94;&#x7528;&#x4E86;&#x4E00;&#x5143;<code>-</code>&#x7B26;&#x53F7;&#x7684;&#x6570;&#x5B57;&#x5B57;&#x9762;&#x91CF;&#xFF08;&#x4F8B;&#x5982;&#xFF1A;<code>-1</code>, <code>-100</code>&#xFF09;</li>
</ul>
<p>&#x5F53;&#x6240;&#x6709;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x90FD;&#x62E5;&#x6709;&#x5B57;&#x9762;&#x91CF;&#x679A;&#x4E3E;&#x503C;&#x65F6;&#xFF0C;&#x5B83;&#x5C31;&#x5E26;&#x6709;&#x4E86;&#x4E00;&#x79CD;&#x7279;&#x6B8A;&#x7684;&#x8BED;&#x4E49;&#x3002;</p>
<p>&#x9996;&#x5148;&#xFF0C;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x6210;&#x4E3A;&#x4E86;&#x7C7B;&#x578B;&#xFF01;
&#x4F8B;&#x5982;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8BF4;&#x67D0;&#x4E9B;&#x6210;&#x5458;<em>&#x53EA;&#x80FD;</em>&#x662F;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;&#x503C;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> ShapeKind {
    Circle,
    Square,
}

<span class="hljs-keyword">interface</span> Circle {
    kind: ShapeKind.Circle;
    radius: <span class="hljs-built_in">number</span>;
}

<span class="hljs-keyword">interface</span> Square {
    kind: ShapeKind.Square;
    sideLength: <span class="hljs-built_in">number</span>;
}

<span class="hljs-keyword">let</span> c: Circle = {
    kind: ShapeKind.Square,
    <span class="hljs-comment">//    ~~~~~~~~~~~~~~~~ Error!</span>
    radius: <span class="hljs-number">100</span>,
}
</code></pre>
<p>&#x53E6;&#x4E00;&#x4E2A;&#x53D8;&#x5316;&#x662F;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x672C;&#x8EAB;&#x53D8;&#x6210;&#x4E86;&#x6BCF;&#x4E2A;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;<em>&#x8054;&#x5408;</em>&#x3002;
&#x867D;&#x7136;&#x6211;&#x4EEC;&#x8FD8;&#x6CA1;&#x6709;&#x8BA8;&#x8BBA;<a href="Advanced%20Types.md#union-types">&#x8054;&#x5408;&#x7C7B;&#x578B;</a>&#xFF0C;&#x4F46;&#x4F60;&#x53EA;&#x8981;&#x77E5;&#x9053;&#x901A;&#x8FC7;&#x8054;&#x5408;&#x679A;&#x4E3E;&#xFF0C;&#x7C7B;&#x578B;&#x7CFB;&#x7EDF;&#x80FD;&#x591F;&#x5229;&#x7528;&#x8FD9;&#x6837;&#x4E00;&#x4E2A;&#x4E8B;&#x5B9E;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x77E5;&#x9053;&#x679A;&#x4E3E;&#x91CC;&#x7684;&#x503C;&#x7684;&#x96C6;&#x5408;&#x3002;
&#x56E0;&#x6B64;&#xFF0C;TypeScript&#x80FD;&#x591F;&#x6355;&#x83B7;&#x5728;&#x6BD4;&#x8F83;&#x503C;&#x7684;&#x65F6;&#x5019;&#x72AF;&#x7684;&#x611A;&#x8822;&#x7684;&#x9519;&#x8BEF;&#x3002;
&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> E {
    Foo,
    Bar,
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">x: E</span>) </span>{
    <span class="hljs-keyword">if</span> (x !== E.Foo || x !== E.Bar) {
        <span class="hljs-comment">//             ~~~~~~~~~~~</span>
        <span class="hljs-comment">// Error! Operator &apos;!==&apos; cannot be applied to types &apos;E.Foo&apos; and &apos;E.Bar&apos;.</span>
    }
}
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x5148;&#x68C0;&#x67E5;<code>x</code>&#x662F;&#x5426;&#x4E0D;&#x662F;<code>E.Foo</code>&#x3002;
&#x5982;&#x679C;&#x901A;&#x8FC7;&#x4E86;&#x8FD9;&#x4E2A;&#x68C0;&#x67E5;&#xFF0C;&#x7136;&#x540E;<code>||</code>&#x4F1A;&#x53D1;&#x751F;&#x77ED;&#x8DEF;&#x6548;&#x679C;&#xFF0C;<code>if</code>&#x8BED;&#x53E5;&#x4F53;&#x91CC;&#x7684;&#x5185;&#x5BB9;&#x4F1A;&#x88AB;&#x6267;&#x884C;&#x3002;
&#x7136;&#x800C;&#xFF0C;&#x8FD9;&#x4E2A;&#x68C0;&#x67E5;&#x6CA1;&#x6709;&#x901A;&#x8FC7;&#xFF0C;&#x90A3;&#x4E48;<code>x</code>&#x5219;<em>&#x53EA;&#x80FD;</em>&#x4E3A;<code>E.Foo</code>&#xFF0C;&#x56E0;&#x6B64;&#x6CA1;&#x7406;&#x7531;&#x518D;&#x53BB;&#x68C0;&#x67E5;&#x5B83;&#x662F;&#x5426;&#x4E3A;<code>E.Bar</code>&#x3002;</p>
<h2 id="&#x8FD0;&#x884C;&#x65F6;&#x7684;&#x679A;&#x4E3E;">&#x8FD0;&#x884C;&#x65F6;&#x7684;&#x679A;&#x4E3E;</h2>
<p>&#x679A;&#x4E3E;&#x662F;&#x5728;&#x8FD0;&#x884C;&#x65F6;&#x771F;&#x6B63;&#x5B58;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#x3002;
&#x4F8B;&#x5982;&#x4E0B;&#x9762;&#x7684;&#x679A;&#x4E3E;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> E {
    X, Y, Z
}
</code></pre>
<p>can actually be passed around to functions</p>
<pre><code class="lang-ts"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">obj: { X: <span class="hljs-built_in">number</span> }</span>) </span>{
    <span class="hljs-keyword">return</span> obj.X;
}

<span class="hljs-comment">// Works, since &apos;E&apos; has a property named &apos;X&apos; which is a number.</span>
f(E);
</code></pre>
<h3 id="&#x53CD;&#x5411;&#x6620;&#x5C04;">&#x53CD;&#x5411;&#x6620;&#x5C04;</h3>
<p>&#x9664;&#x4E86;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x4EE5;&#x5C5E;&#x6027;&#x540D;&#x505A;&#x4E3A;&#x5BF9;&#x8C61;&#x6210;&#x5458;&#x7684;&#x5BF9;&#x8C61;&#x4E4B;&#x5916;&#xFF0C;&#x6570;&#x5B57;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x8FD8;&#x5177;&#x6709;&#x4E86;<em>&#x53CD;&#x5411;&#x6620;&#x5C04;</em>&#xFF0C;&#x4ECE;&#x679A;&#x4E3E;&#x503C;&#x5230;&#x679A;&#x4E3E;&#x540D;&#x5B57;&#x3002;
&#x4F8B;&#x5982;&#xFF0C;&#x5728;&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">enum</span> Enum {
    A
}
<span class="hljs-keyword">let</span> a = Enum.A;
<span class="hljs-keyword">let</span> nameOfA = Enum[a]; <span class="hljs-comment">// &quot;A&quot;</span>
</code></pre>
<p>TypeScript&#x53EF;&#x80FD;&#x4F1A;&#x5C06;&#x8FD9;&#x6BB5;&#x4EE3;&#x7801;&#x7F16;&#x8BD1;&#x4E3A;&#x4E0B;&#x9762;&#x7684;JavaScript&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> Enum;
(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">Enum</span>) </span>{
    Enum[Enum[<span class="hljs-string">&quot;A&quot;</span>] = <span class="hljs-number">0</span>] = <span class="hljs-string">&quot;A&quot;</span>;
})(Enum || (Enum = {}));
<span class="hljs-keyword">var</span> a = Enum.A;
<span class="hljs-keyword">var</span> nameOfA = Enum[a]; <span class="hljs-comment">// &quot;A&quot;</span>
</code></pre>
<p>&#x751F;&#x6210;&#x7684;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x88AB;&#x7F16;&#x8BD1;&#x6210;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x5B83;&#x5305;&#x542B;&#x4E86;&#x6B63;&#x5411;&#x6620;&#x5C04;&#xFF08;<code>name</code> -&gt; <code>value</code>&#xFF09;&#x548C;&#x53CD;&#x5411;&#x6620;&#x5C04;&#xFF08;<code>value</code> -&gt; <code>name</code>&#xFF09;&#x3002;
&#x5F15;&#x7528;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x603B;&#x4F1A;&#x751F;&#x6210;&#x4E3A;&#x5BF9;&#x5C5E;&#x6027;&#x8BBF;&#x95EE;&#x5E76;&#x4E14;&#x6C38;&#x8FDC;&#x4E5F;&#x4E0D;&#x4F1A;&#x5185;&#x8054;&#x4EE3;&#x7801;&#x3002;</p>
<p>&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;<em>&#x4E0D;&#x4F1A;</em>&#x4E3A;&#x5B57;&#x7B26;&#x4E32;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x751F;&#x6210;&#x53CD;&#x5411;&#x6620;&#x5C04;&#x3002;</p>
<h3 id="const&#x679A;&#x4E3E;"><code>const</code>&#x679A;&#x4E3E;</h3>
<p>&#x5927;&#x591A;&#x6570;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x679A;&#x4E3E;&#x662F;&#x5341;&#x5206;&#x6709;&#x6548;&#x7684;&#x65B9;&#x6848;&#x3002;
&#x7136;&#x800C;&#x5728;&#x67D0;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#x9700;&#x6C42;&#x5F88;&#x4E25;&#x683C;&#x3002;
&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x5728;&#x989D;&#x5916;&#x751F;&#x6210;&#x7684;&#x4EE3;&#x7801;&#x4E0A;&#x7684;&#x5F00;&#x9500;&#x548C;&#x989D;&#x5916;&#x7684;&#x975E;&#x76F4;&#x63A5;&#x7684;&#x5BF9;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x7684;&#x8BBF;&#x95EE;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>const</code>&#x679A;&#x4E3E;&#x3002;
&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x901A;&#x8FC7;&#x5728;&#x679A;&#x4E3E;&#x4E0A;&#x4F7F;&#x7528;<code>const</code>&#x4FEE;&#x9970;&#x7B26;&#x6765;&#x5B9A;&#x4E49;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">const</span> <span class="hljs-keyword">enum</span> Enum {
    A = <span class="hljs-number">1</span>,
    B = A * <span class="hljs-number">2</span>
}
</code></pre>
<p>&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x53EA;&#x80FD;&#x4F7F;&#x7528;&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x5E76;&#x4E14;&#x4E0D;&#x540C;&#x4E8E;&#x5E38;&#x89C4;&#x7684;&#x679A;&#x4E3E;&#xFF0C;&#x5B83;&#x4EEC;&#x5728;&#x7F16;&#x8BD1;&#x9636;&#x6BB5;&#x4F1A;&#x88AB;&#x5220;&#x9664;&#x3002;
&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x6210;&#x5458;&#x5728;&#x4F7F;&#x7528;&#x7684;&#x5730;&#x65B9;&#x4F1A;&#x88AB;&#x5185;&#x8054;&#x8FDB;&#x6765;&#x3002;
&#x4E4B;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x8FD9;&#x4E48;&#x505A;&#x662F;&#x56E0;&#x4E3A;&#xFF0C;&#x5E38;&#x91CF;&#x679A;&#x4E3E;&#x4E0D;&#x5141;&#x8BB8;&#x5305;&#x542B;&#x8BA1;&#x7B97;&#x6210;&#x5458;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">const</span> <span class="hljs-keyword">enum</span> Directions {
    Up,
    Down,
    Left,
    Right
}

<span class="hljs-keyword">let</span> directions = [Directions.Up, Directions.Down, Directions.Left, Directions.Right]
</code></pre>
<p>&#x751F;&#x6210;&#x540E;&#x7684;&#x4EE3;&#x7801;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> directions = [<span class="hljs-number">0</span> <span class="hljs-comment">/* Up */</span>, <span class="hljs-number">1</span> <span class="hljs-comment">/* Down */</span>, <span class="hljs-number">2</span> <span class="hljs-comment">/* Left */</span>, <span class="hljs-number">3</span> <span class="hljs-comment">/* Right */</span>];
</code></pre>
<h1 id="&#x5916;&#x90E8;&#x679A;&#x4E3E;">&#x5916;&#x90E8;&#x679A;&#x4E3E;</h1>
<p>&#x5916;&#x90E8;&#x679A;&#x4E3E;&#x7528;&#x6765;&#x63CF;&#x8FF0;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;&#x679A;&#x4E3E;&#x7C7B;&#x578B;&#x7684;&#x5F62;&#x72B6;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">enum</span> Enum {
    A = <span class="hljs-number">1</span>,
    B,
    C = <span class="hljs-number">2</span>
}
</code></pre>
<p>&#x5916;&#x90E8;&#x679A;&#x4E3E;&#x548C;&#x975E;&#x5916;&#x90E8;&#x679A;&#x4E3E;&#x4E4B;&#x95F4;&#x6709;&#x4E00;&#x4E2A;&#x91CD;&#x8981;&#x7684;&#x533A;&#x522B;&#xFF0C;&#x5728;&#x6B63;&#x5E38;&#x7684;&#x679A;&#x4E3E;&#x91CC;&#xFF0C;&#x6CA1;&#x6709;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;&#x7684;&#x6210;&#x5458;&#x88AB;&#x5F53;&#x6210;&#x5E38;&#x6570;&#x6210;&#x5458;&#x3002;
&#x5BF9;&#x4E8E;&#x975E;&#x5E38;&#x6570;&#x7684;&#x5916;&#x90E8;&#x679A;&#x4E3E;&#x800C;&#x8A00;&#xFF0C;&#x6CA1;&#x6709;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;&#x65F6;&#x88AB;&#x5F53;&#x505A;&#x9700;&#x8981;&#x7ECF;&#x8FC7;&#x8BA1;&#x7B97;&#x7684;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Generics.html" class="navigation navigation-prev " aria-label="Previous page: 泛型">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Type Inference.html" class="navigation navigation-next " aria-label="Next page: 类型推论">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"枚举","level":"1.3.7","depth":2,"next":{"title":"类型推论","level":"1.3.8","depth":2,"path":"doc/handbook/Type Inference.md","ref":"./doc/handbook/Type Inference.md","articles":[]},"previous":{"title":"泛型","level":"1.3.6","depth":2,"path":"doc/handbook/Generics.md","ref":"./doc/handbook/Generics.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Patrick Zhong","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"preface.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"TypeScript Handbook","language":"zh-hans","gitbook":">3.0.0","description":"Translation of official TypeScript Handbook"},"file":{"path":"doc/handbook/Enums.md","mtime":"2018-10-13T09:48:54.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T09:57:42.904Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

